﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyModel;
using System.Data.SqlClient;
using System.Data;
using MyDBUtil;
using System.Data.Common;

namespace MyDAL.user
{
    public class userDAL
    {
        public userDAL(){}

        public bool addUser(MyModel.user.user model) {
            bool result = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into xs_user(");
            strSql.Append("username,password,truename,sex,phone,status,roleid,isaction,operater,operatertime,sign1,sign2,sign3)");
            strSql.Append(" values (");
            strSql.Append("@username,@password,@truename,@sex,@phone,@status,@roleid,@isaction,@operater,@operatertime,@sign1,@sign2,@sign3)");
            //strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@username", SqlDbType.VarChar,50),
					new SqlParameter("@password", SqlDbType.VarChar,50),
					new SqlParameter("@truename", SqlDbType.VarChar,50),
					new SqlParameter("@sex", SqlDbType.VarChar,50),
					new SqlParameter("@phone", SqlDbType.VarChar,200),
					new SqlParameter("@status", SqlDbType.VarChar,10),
					new SqlParameter("@roleid", SqlDbType.Int),
					new SqlParameter("@isaction", SqlDbType.Int),
					new SqlParameter("@operater", SqlDbType.VarChar,50),
					new SqlParameter("@operatertime", SqlDbType.VarChar,50),
					new SqlParameter("@sign1", SqlDbType.VarChar,50),
					new SqlParameter("@sign2", SqlDbType.VarChar,50),
					new SqlParameter("@sign3", SqlDbType.VarChar,50)};
            parameters[0].Value = model.Username;
            parameters[1].Value = model.Password;
            parameters[2].Value = model.Truename;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.Phone;
            parameters[5].Value = model.Status;
            parameters[6].Value = model.Roleid;
            parameters[7].Value = model.Isaction;
            parameters[8].Value = model.Operater;
            parameters[9].Value = model.Operatertime;
            parameters[10].Value = model.Sign1;
            parameters[11].Value = model.Sign2;
            parameters[12].Value = model.Sign3;
            DBHelper db = new DBHelper();
            DbCommand cmd = db.GetSqlStringCommond(strSql.ToString());
            db.AddParameters(cmd, parameters);
            object obj = db.ExecuteScalar(cmd);
            if (obj == null || Convert.ToInt32(obj)<1)
            {
                result = false;
            }
            else
            {
                result = true;
            }
            return result;
        }
    }
}
